<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ include file="/WEB-INF/jsp/commons/taglibs.jsp"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>E-天下商旅</title>
<link href="${ctx}/resources/css/page_member.css" rel="stylesheet" type="text/css">
<link href="${ctx}/resources/css/jbox_skin_blue/jbox.css" rel="stylesheet" type="text/css">
</head>

<body>

<jsp:include page="../commons/header.jsp" >
     <jsp:param name="currentMenu" value="menu3"/>
</jsp:include>



<div class="main_box">
<div class="main cf">

	<jsp:include page="../commons/left.jsp"></jsp:include>
		<div class="right">
		<div class="right_box">
			<div class="title"><span><a href="#">申请成为代理中心</a></span></div>
			<div class="content cf">
				<div class="applyagentcenter_box">
					<img class="top_img" src="${ctx}/resources/img/top4.png">
					<form action="${ctx}/agents/applyAgent"  onsubmit="">
                        <div>
							<label><i>* </i>姓名</label>
                            <input type="text" class="input" name="name" /><span></span>
                        </div>
                        <div>
							<label><i>* </i>上级服务中心</label>
                            <input type="text" class="input" name="parentCenter" id="parentCenter"/><span></span>
                        </div>
                        <div>
							<label><i>* </i>证件号</label>
                            <input type="text" class="input" name="cardno" /><span></span>
                        </div>
                        <div>
							<label><i>* </i>联系电话</label>
                            <input type="text" class="input" name="phone" /><span></span>
                        </div>
                        <div>
							<label><i>* </i>电子邮箱</label>
                            <input type="text" class="input" name="email"  /><span></span>
                        </div>
                        <div>
							<label><i>* </i>所属区域（省、市、县）</label>
                            <input type="text" class="input" name="address" /><span></span>
                        </div>
                        <div>
 							<label>&nbsp;</label>
							<input type="submit" class="submit btn_orange" value="提 交" />
                        </div>

					</form>
				</div>
			</div>
		</div>
	</div>
		
</div>
</div>

<jsp:include page="../commons/footer.jsp"></jsp:include>

<script src="${ctx}/resources/script/validate/jquery-1.4.min.js" type="text/javascript"></script>
<script src="${ctx}/resources/script/common.js"></script>
<script src="${ctx}/resources/script/jquery.jBox-2.3.min.js"></script>
<script src="${ctx}/resources/script/jquery.jBox-zh-CN.js"></script> 
<script type="text/javascript" src="${ctx}/resources/script/validate/jquery.validate.js"></script>
<script type="text/javascript" src="${ctx}/resources/script/validate/jquery.metadata.js"></script>
<script type="text/javascript" src="${ctx}/resources/script/validate/additional-methods.js" charset="utf-8"></script>
<script type="text/javascript" src="${ctx}/resources/script/validate/messages_cn.js" charset="utf-8"></script>
<script>
$.validator.setDefaults({
	submitHandler: function() { ajaxApplyAgent(); }
	});

function ajaxApplyAgent(){
	var url = "${ctx}/agents/applyAgent";
    $.ajax({
        type: "post",
        async:false,
        url: url,
        dataType: "json",
        data:$("form").serialize(),
        success: function(getmsg){  
            if(getmsg.code==0) {
        		//$.jBox(getmsg.context, {
        		//	title: "提示消息",
        		//	bottomText: ""
        		//});
        		alert(getmsg.context);
            } 
            else
            {
        		//$.jBox("申请成功", {
        		//	title: "提示消息",
        		//	bottomText: ""
        		//});
        		alert("申请成功");
        		
            }
            window.location.href="${ctx}/agents/index?timestap="+(new Date()).getTime();
        }
    });
}
	
$(function() {			
	   $("form").validate({
		   rules:{
			   name:{
				   required : true,
				   rangelength:[2,20]
			   },
			   parentCenter:{
				   required:true,
				   remote:{
						url: "${ctx}/agents/checkParentAgent", //后台处理程序    
				        type:"post",
				        dataType: "json",       				 //接受数据格式      
				        data:  {                     			 //要传递的数据   
				        	parentAgent: function() {   
				        				return $("#parentCenter").val();   
				        	  		  }		  
				        } 
				   }
			   },
			   cardno:{
				   required:true,
				   isIdCardNo:true
			   },
			   phone:{
				   required:true,
				   mobile:true
			   },
			   email:{
				   required:true,
				   email:true
			   },
			   address:{
				   required:true,
			   }
			   
		   },
		   errorPlacement : function(error, element) {
				error.appendTo(element.next("span"));
			},
			messages : {
				parentCenter:{
					remote:"上级服务中心必须是通过批准的代理中心"
				}
			}
		  });	
	   });
	
</script>
</body>
</html>

